package org.example;

import java.util.Random;

import static java.util.Arrays.copyOfRange;

public class test7 {
    public static void main(String[] args) {
       /* //将数组中元素反转
        int []arr = {1,2,3,4,5,6,7,8,9,10};
        for (int i = 0,j=arr.length-1;i<j;i++,j--) {
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
        //打乱数组数据
        Random rand = new Random();
        for (int i = 0; i < arr.length; i++) {
            int randomIndex = rand.nextInt(arr.length);
            int temp = arr[i];
            arr[i] = arr[randomIndex];
            arr[randomIndex] = temp;
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }*/
       /*
        //拷贝数组1
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        int[] copyArr = copyOfRange(arr, 2, 6);
        for (int i = 0; i < copyArr.length; i++) {
            System.out.print(copyArr[i] + " ");
        }
    }
        public static int[] copyOfRange(int[] arr,int from,int to){
            int[] newArr = new int[to - from];
            int index = 0;
            for (int i = from; i < to; i++) {
                newArr[index] = arr[i];
                index++;
            }
            return newArr;
    }*/
        //拷贝数组2
        int[] arr = {1, 2, 3, 4, 5, 6, 7,8,9};
        int[]arr2 = new int[9];
        //从arr数组的第0个元素开始拷贝，拷贝到arr2数组的第0个元素开始，拷贝9个元素
        System.arraycopy(arr,0,arr2,0,9);
        for (int i = 0; i < arr2.length; i++) {
            System.out.print(arr2[i]+" ");
        }
    }
}
